<?php
/**
 * ===============================================
 * 版权所有 2019-2050 青岛铁锤科技有限公司，并保留所有权利。
 * 网站地址: http://www.huaxianling.com
 * ===============================================
 * Author: Happy dong
 * Created Time: 2019-06-26 13:57
 * Modified Time: 2019-06-26 13:57
 * Version: 2.0
 */

namespace App\Modules\Member\Criterias;


use Flower\Core\Repository\Contracts\CriteriaInterface;
use Flower\Core\Repository\Contracts\RepositoryInterface;

class getScheduleCriteria implements CriteriaInterface
{
	protected $map;

	public function __construct($storeId, $startTime, $endTime,$barberId=null,$status =null)
	{
		$this->map = [
			'barber_id'  => $barberId,
			'status'     => $status,
			'store_id'   => $storeId,
			'start_time' => strtotime($startTime),
			'end_time'   => strtotime($endTime)
		];
	}

	public function apply($model, RepositoryInterface $repository)
	{
		$where['store_id'] = $this->map['store_id'];
		empty($this->map['barber_id']) ? : $where['user_id'] = $this->map['barber_id'];
		if(isset($this->map['status'])) $where['status'] = $this->map['status'];
		return $model->with('user:id,nick')->where($where)->where('plan_date','>=',$this->map['start_time'])->where('plan_date','<=',$this->map['end_time'])->orderBy('plan_date','asc');


	}

}
